// ==============================================================================================
// ControlTreeNode.cs
//
// Created by: NI, 2007.03.27
// Revised by: NI, 2007.11.23
// ==============================================================================================
using System.Windows.Forms;
using RibbonExplorer.Entities;
using RibbonExplorer.InfoPanel;

namespace RibbonExplorer.Tree
{
  // ==============================================================================================
  /// <summary>
  /// This tree node represents a ribbon control.
  /// </summary>
  // ==============================================================================================
  public class ControlTreeNode : TreeNode, IInfoPanelSupport
  {
    #region Private fields

    private RibbonControl _Control;

    #endregion

    #region Lifecycle methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates the tree node instance.
    /// </summary>
    /// <param name="control">Ribbon control instance for this tree node.</param>
    // --------------------------------------------------------------------------------------------
    public ControlTreeNode(RibbonControl control)
      : base(control.Id)
    {
      _Control = control;
      Tag = _Control;

      // --- Select the default control image
      ImageKey = control.Properties.Type.ToString();
      SelectedImageKey = ImageKey;

      // --- Create contextual tab nodes
      foreach (RibbonControl child in _Control.Controls.Values)
      {
        Nodes.Add(new ControlTreeNode(child));
      }
    }

    #endregion

    #region Public properties

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the ribbon control instance represented by this node.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public RibbonControl Control
    {
      get { return _Control; }
    }

    #region IInfoPanelSupport implementation

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates an infopanel instance for this tree node type.
    /// </summary>
    /// <param name="node">Tree node instance</param>
    /// <param name="navigationService">Navigation service instance</param>
    /// <returns>
    /// User control instance
    /// </returns>
    // --------------------------------------------------------------------------------------------
    public UserControl GetInfoPanelInstance(TreeNode node, INavigationSupport navigationService)
    {
      GenericInfoPanel control = new GenericInfoPanel(navigationService, node);
      control.HeaderText = string.Format("{0}: {1}", _Control.Properties.Type, node.Text);
      return control;
    }

    #endregion

    #endregion
  }
}
